#!/bin/bash
httpPort=8280
managementPort=7280
dockerRegistryPath=10.196.22.81/emis
containerName=emis_edda_hsbc
versionStr=CID_TAG_VERSION
path="/opt/EMISLogs/EMIS-EDDA-HSBCLogs"
config_path="/opt/EMIS-EDDA-HSBC/config/"
#token_nh-(南汇token) token_wg-(万国token) token_zp-(周浦token)
token_nh=
token_wg=9d659a7b-d253-dbf2-7f83-0194f398ad69
token_zp=99e5ba1d-cbbf-33ef-d72d-8f104e7c90ac

# 根据ip判断机房，确定Consul ACL Token
localIp=$(/usr/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v 172.17|grep -v 172.16|grep -v inet6|awk '{print $2}'|tr -d "addr:")
echo ${localIp}:${httpPort}

# 拉取镜像
docker pull ${dockerRegistryPath}/${containerName}:${versionStr}
# 如果已经有container在运行，删掉
output=$(docker ps -a |grep ${containerName})
echo $output
if [ ! -n "$output" ]; then
    echo "container not exit"
else
    docker stop ${containerName}
    docker rm ${containerName}
fi
# 日志挂载目录，不存在则创建
if [ -d ${path} ];then
    echo dir ${path} exist!
else
    echo dir ${path} not exist!
    mkdir -p ${path}
fi

#启动
docker run --net=host \
-e JAVA_LOCALIP=${localIp} \
-e JAVA_OPTS='-Dspring.profiles.active=pre' \
--restart=always \
-itd --name ${containerName} \
-p ${httpPort}:80 \
-p ${managementPort}:${managementPort} \
-v ${path}:/app/logs \
-v ${config_path}:/app/config \
${dockerRegistryPath}/${containerName}:${versionStr}